import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_module/base/base.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:provider/provider.dart';

class ProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
  int count = 0;

  ProviderModel();

  void up() {
    count++;
    notifyListeners();
  }

  @override
  void debugFillProperties(DiagnosticPropertiesBuilder properties) {
    super.debugFillProperties(properties);
    properties.add(IntProperty("count", count));
  }
}

class Provider2Model with ChangeNotifier, DiagnosticableTreeMixin {
  int count = 0;

  Provider2Model();

  void up() {
    count++;
    notifyListeners();
  }

  @override
  void debugFillProperties(DiagnosticPropertiesBuilder properties) {
    super.debugFillProperties(properties);
    properties.add(IntProperty("count", count));
  }
}

class PageProvideState extends BaseWidget {
  const PageProvideState({super.key});

  @override
  Widget setContent(BuildContext context) {
    return MultiProvider(
      providers: [
        ChangeNotifierProvider(create: (_) => ProviderModel()),
        ChangeNotifierProvider(create: (_) => Provider2Model()),
      ],
      builder: (context, widget) {
        print("创建 widget");
        return Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            Text(
              "Provide",
              style: TextStyle(color: Colors.black, fontSize: 36.w),
            ),
            Expanded(child: Container()),
            Text(
              "${context.watch<ProviderModel>().count}",
              style: TextStyle(color: Color(0xFF333333), fontSize: 24.w),
            ),
            TextButton(
              onPressed: () {
                context.read<ProviderModel>().up();
              },
              child: Text("Count ++", style: TextStyle(fontSize: 24.w)),
            ),
            Text(
              "${context.watch<Provider2Model>().count}",
              style: TextStyle(color: Color(0xFF333333), fontSize: 24.w),
            ),
            TextButton(
              onPressed: () {
                context.read<Provider2Model>().up();
              },
              child: Text("Count ++", style: TextStyle(fontSize: 24.w)),
            ),
            Expanded(child: Container()),
          ],
        );
      },
    );
  }
}
